Skip to content

Fixes for kci #2904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 18, 2025
Merged

Fixes for kci #2904

merged 8 commits into from
Jun 18, 2025

Conversation

nuclearcat
Copy link
Member

@nuclearcat nuclearcat commented Jun 13, 2025

This is various fixes for kci usability reported by @broonie

Even with included patches, still major issue remains, config of pipeline need to be "added" to kernelci-config for job definitions and runtimes.
And runtime templates from kernelci-pipeline need to be added to kernelci-core/config/runtime.
I need to figure out how to do that user-friendly way

Fixes: #2903

@nuclearcat nuclearcat marked this pull request as draft June 13, 2025 23:16
@nuclearcat
Copy link
Member Author

Now it works (with example toml config):
./kci job generate 684ca438dba9af5ad63511e5 --runtime lava-collabora -c ../kernelci-pipeline/config/
Sure you need to have cloned outside kernelci-pipeline

@@ -180,6 +180,7 @@ def group(self, *args, cls=None, **kwargs):

@click.group(cls=KciGroup)
@Args.settings
# @Args.config # Removed to allow subcommands to receive -c/--yaml-config
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to use -c successfully without this change.

Could you provide more context on how does this change fix -c logic?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i reverse

./kci job generate 684ca438dba9af5ad63511e5 --runtime lava-collabora -c ../kernelci-pipeline/config/ 
Traceback (most recent call last):
  File "/home/nuclearcat/Documents/TEST/kernelci-core/./kci", line 35, in <module>
    main()
  File "/home/nuclearcat/Documents/TEST/kernelci-core/./kci", line 31, in main
    kci()  # pylint: disable=no-value-for-parameter
    ^^^^^
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/click/core.py", line 1654, in invoke
    super().invoke(ctx)
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: kci() got an unexpected keyword argument 'config'

and as global wont work either:

./kci -c ../kernelci-pipeline/config/ job generate 684ca438dba9af5ad63511e5 --runtime lava-collabora
Traceback (most recent call last):
  File "/home/nuclearcat/Documents/TEST/kernelci-core/./kci", line 35, in <module>
    main()
  File "/home/nuclearcat/Documents/TEST/kernelci-core/./kci", line 31, in main
    kci()  # pylint: disable=no-value-for-parameter
    ^^^^^
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/click/core.py", line 1654, in invoke
    super().invoke(ctx)
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: kci() got an unexpected keyword argument 'config'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see and now it's even more confusing to me - here's what works for me:

./kci job generate -c ../kernelci-pipeline/config/ 684a6749dba9af5ad62e4a68

so:

./kci $command $subcommand $global_options $subcommand_argument

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git a/kernelci/cli/__init__.py b/kernelci/cli/__init__.py
index a3c02b58..a9d405a9 100644
--- a/kernelci/cli/__init__.py
+++ b/kernelci/cli/__init__.py
@@ -180,7 +180,7 @@ class KciGroup(click.core.Group):
 
 @click.group(cls=KciGroup)
 @Args.settings
-# @Args.config  # Removed to allow subcommands to receive -c/--yaml-config
[email protected]
 @click.pass_context
 def kci(ctx, settings):
     """Entry point for the kci command line tool"""

If i put it back it doesnt work for me:

./kci job generate -c ../kernelci-pipeline/config/ 684a6749dba9af5ad62e4a68
Traceback (most recent call last):
  File "/home/nuclear/Documents/kernelci-core/./kci", line 35, in <module>
    main()
    ~~~~^^
  File "/home/nuclear/Documents/kernelci-core/./kci", line 31, in main
    kci()  # pylint: disable=no-value-for-parameter
    ~~~^^
  File "/usr/lib/python3/dist-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1694, in invoke
    super().invoke(ctx)
    ~~~~~~~~~~~~~~^^^^^
  File "/usr/lib/python3/dist-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
TypeError: kci() got an unexpected keyword argument 'config'

@@ -75,13 +75,22 @@ class Runtime(abc.ABC):
TEMPLATES = ['config/runtime', '/etc/kernelci/runtime']

# pylint: disable=unused-argument
def __init__(self, config, user=None, token=None):
def __init__(self, config, user=None, token=None, custom_template_dir=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide more context on how this feature is intended to be used and what key benefits do you see by enabling additional runtime config directory tree.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default jinja will search templates in kernelci-core/config/runtime only, it wont search in pipeline config.
This is what will happen:

Traceback (most recent call last):
  File "/home/nuclearcat/Documents/TEST/kernelci-core/./kci", line 35, in <module>
    main()
  File "/home/nuclearcat/Documents/TEST/kernelci-core/./kci", line 31, in main
    kci()  # pylint: disable=no-value-for-parameter
    ^^^^^
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nuclearcat/Documents/TEST/kernelci-core/kernelci/cli/__init__.py", line 150, in invoke
    super().invoke(ctx)
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nuclearcat/Documents/TEST/kernelci-core/kernelci/cli/__init__.py", line 78, in call
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/nuclearcat/Documents/TEST/kernelci-core/kernelci/cli/job.py", line 123, in generate
    job_data = runtime.generate(job, params)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nuclearcat/Documents/TEST/kernelci-core/kernelci/runtime/lava.py", line 327, in generate
    template = self._get_template(job.config)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nuclearcat/Documents/TEST/kernelci-core/kernelci/runtime/__init__.py", line 106, in _get_template
    return jinja2_env.get_template(job_config.template)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/jinja2/environment.py", line 1016, in get_template
    return self._load_template(name, globals)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/jinja2/environment.py", line 975, in _load_template
    template = self.loader.load(self, name, self.make_globals(globals))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nuclearcat/.local/lib/python3.12/site-packages/jinja2/loaders.py", line 607, in load
    raise TemplateNotFound(name)
jinja2.exceptions.TemplateNotFound: generic.jinja2

In job definition we have baseline.jinja2 for this particular job, which need to be retrieved from custom config directory (../kernelci-pipeline/config), or we can try to do a mess and merge configs from pipeline to core manually, which is IMHO very wrong.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it's already messy enough - I don't have an answer on how to proceed with it yet

Comment on lines 131 to 145
def _get_runtime(runtime, config, secrets):
configs = kernelci.config.load(config)
runtime_config = configs['runtimes'][runtime]
runtime = kernelci.runtime.get_runtime(
runtime_config, token=secrets.api.runtime_token,
custom_template_dir=config[0] if config else None
)
return runtime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change reverts all the checks you introduced earlier. I believe this wasn't intended (maybe rebase conflict resolution hiccup?) - please help me understand it if that's not the case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter complained there is too many branches in main function. I just moved part of logic from kbuild to separate function, and decided to remove these checks, and to work later to make them more elegant and consistent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. You added useful checks in "Add proper error if runtime not found" commit
  2. You received linter complaint
  3. You extracted part of the logic to a separate function and reverted your initial change

In this case I'd say it's reasonable to ignore linter hints - there is no strict rule that codebase has to follow such suggestions to the letter.

I also disagree that there will be an opportunity

to work later to make them more elegant and consistent

Project's development history so far strongly suggests quite the opposite of it

@nuclearcat
Copy link
Member Author

Full steps to reproduce:
git clone https://github.com/nuclearcat/kernelci-core.git
git clone https://github.com/kernelci/kernelci-pipeline.git
cd kernelci-core
git checkout fixes-for-kci
cp kernelci.toml.sample kernelci.toml
./kci job generate 684ca438dba9af5ad63511e5 --runtime lava-collabora -c ../kernelci-pipeline/config/

@nuclearcat nuclearcat marked this pull request as ready for review June 17, 2025 21:15
@nuclearcat nuclearcat force-pushed the fixes-for-kci branch 2 times, most recently from 5735413 to c7867ab Compare June 17, 2025 23:26
Copy link
Contributor

@pawiecz pawiecz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nuclearcat I understand that my comments to this series might seem like a "patch sculpting" but that's not my intention - I try to work out with you a consistent and clear way of addressing issues you noticed and attempted to fix in the code base.

If this is not what you expect from a reviewer for your patch series I'm fine to hand it over and revert change requests.

@@ -180,6 +180,7 @@ def group(self, *args, cls=None, **kwargs):

@click.group(cls=KciGroup)
@Args.settings
# @Args.config # Removed to allow subcommands to receive -c/--yaml-config
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see and now it's even more confusing to me - here's what works for me:

./kci job generate -c ../kernelci-pipeline/config/ 684a6749dba9af5ad62e4a68

so:

./kci $command $subcommand $global_options $subcommand_argument

@@ -75,13 +75,22 @@ class Runtime(abc.ABC):
TEMPLATES = ['config/runtime', '/etc/kernelci/runtime']

# pylint: disable=unused-argument
def __init__(self, config, user=None, token=None):
def __init__(self, config, user=None, token=None, custom_template_dir=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it's already messy enough - I don't have an answer on how to proceed with it yet

Comment on lines 131 to 145
def _get_runtime(runtime, config, secrets):
configs = kernelci.config.load(config)
runtime_config = configs['runtimes'][runtime]
runtime = kernelci.runtime.get_runtime(
runtime_config, token=secrets.api.runtime_token,
custom_template_dir=config[0] if config else None
)
return runtime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. You added useful checks in "Add proper error if runtime not found" commit
  2. You received linter complaint
  3. You extracted part of the logic to a separate function and reverted your initial change

In this case I'd say it's reasonable to ignore linter hints - there is no strict rule that codebase has to follow such suggestions to the letter.

I also disagree that there will be an opportunity

to work later to make them more elegant and consistent

Project's development history so far strongly suggests quite the opposite of it

Signed-off-by: Denys Fedoryshchenko <[email protected]>
Also in example correct config for current production.

Signed-off-by: Denys Fedoryshchenko <[email protected]>
Signed-off-by: Denys Fedoryshchenko <[email protected]>
Signed-off-by: Denys Fedoryshchenko <[email protected]>
Signed-off-by: Denys Fedoryshchenko <[email protected]>
Copy link
Contributor

@pawiecz pawiecz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nuclearcat Thanks for addressing most of my concerns. I understand the need for "cutting corners" to make the Users happy. I have no intention of blocking this patch series anymore.

@nuclearcat nuclearcat added this pull request to the merge queue Jun 18, 2025
Merged via the queue into kernelci:main with commit 36c1ee6 Jun 18, 2025
4 checks passed
@nuclearcat nuclearcat deleted the fixes-for-kci branch June 18, 2025 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make kci tool work by default, after clone
2 participants